package cn.dansj.repository;

import cn.dansj.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.List;

@Repository
public interface RoleRepository extends JpaRepository<Role, String>, JpaSpecificationExecutor<Role> {

    @Modifying
    @Query(value = "update Role set status=:status,updateTime=:update_time where sequence = :sequence")
    void updateStatus(@Param("sequence") String sequence,
                      @Param("status") String status,
                      @Param("update_time") Timestamp update_time);

    @Modifying
    @Query(value = "update Role set interfaceVip=:vip,updateTime=:update_time where sequence = :sequence")
    void updateVip(@Param("sequence") String sequence,
                   @Param("vip") int vip,
                   @Param("update_time") Timestamp update_time);

    Role findBySequence(String sequence);

    Role findByName(String name);

    @Query(value = "select t.name from Role t where t.interfaceVip=1")
    List<String> getInterfaceVip();
}
